package com.bw.lib_net.http

import com.bw.lib_net.interceptor.HttpHeaderInterceptor
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
import javax.inject.Qualifier
import javax.inject.Singleton
import javax.net.ssl.HostnameVerifier
import javax.net.ssl.SSLSession

@Module
@InstallIn(SingletonComponent::class)
object NetModule {

    @Provides
    @Singleton
    @CommonOkHttpClient
    fun provideOkHttpClient(): OkHttpClient {
        return OkHttpClient.Builder()
            .readTimeout(60, TimeUnit.SECONDS)
            .writeTimeout(60, TimeUnit.SECONDS)
            .connectTimeout(60, TimeUnit.SECONDS)
            .addInterceptor(HttpHeaderInterceptor())
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .build()
    }


    @Qualifier
    @Retention(AnnotationRetention.RUNTIME)
    annotation class CommonOkHttpClient



    @Provides
    @Singleton
    @CommonRetrofit
    fun provideRetrofit(@CommonOkHttpClient client:OkHttpClient): Retrofit {
        return Retrofit.Builder()
            .baseUrl("http://10.161.9.80:2209")
            .client(client)
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }





    @Qualifier
    @Retention(AnnotationRetention.RUNTIME)
    annotation class CommonRetrofit




}